```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>并发编程艺术：多线程设计与架构</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background-color: #f8fafc;
            color: #1e293b;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
        }
        .code-block {
            background-color: #1e293b;
            color: #f8fafc;
            border-left: 4px solid #7c3aed;
        }
        .pattern-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .highlight {
            position: relative;
        }
        .highlight::after {
            content: '';
            position: absolute;
            left: 0;
            bottom: 0;
            width: 100%;
            height: 30%;
            background-color: rgba(124, 58, 237, 0.2);
            z-index: -1;
            transform: scaleX(0);
            transform-origin: left;
            transition: transform 0.3s ease;
        }
        .highlight:hover::after {
            transform: scaleX(1);
        }
    </style>
</head>
<body class="antialiased">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-4 sm:px-6 lg:px-8">
        <div class="max-w-6xl mx-auto">
            <div class="flex flex-col md:flex-row items-center">
                <div class="md:w-1/2 mb-10 md:mb-0">
                    <div class="flex items-center space-x-2 mb-4">
                        <div class="w-8 h-1 bg-purple-300"></div>
                        <span class="text-purple-200 font-medium">并发编程</span>
                    </div>
                    <h1 class="text-4xl md:text-5xl lg:text-6xl font-bold mb-6 leading-tight font-serif">多线程设计与架构的艺术</h1>
                    <p class="text-xl text-purple-100 mb-8 max-w-lg">在现代高并发系统中，掌握多线程设计模式和架构技巧是构建高性能应用的基石。</p>
                    <div class="flex space-x-4">
                        <button class="bg-white text-purple-600 hover:bg-purple-50 px-6 py-3 rounded-lg font-medium transition duration-300 transform hover:-translate-y-1">
                            <i class="fas fa-book-open mr-2"></i> 深入阅读
                        </button>
                        <button class="border-2 border-white text-white hover:bg-white hover:text-purple-600 px-6 py-3 rounded-lg font-medium transition duration-300">
                            <i class="fas fa-code mr-2"></i> 查看代码
                        </button>
                    </div>
                </div>
                <div class="md:w-1/2">
                    <div class="bg-white/10 backdrop-blur-sm p-6 rounded-xl border border-white/20">
                        <div class="mermaid">
                            graph TD
                                A[并发编程] --> B[多线程设计模式]
                                A --> C[架构设计]
                                B --> B1[单例模式]
                                B --> B2[生产者-消费者]
                                B --> B3[观察者模式]
                                B --> B4[线程池模式]
                                C --> C1[线程安全]
                                C --> C2[无阻塞架构]
                                C --> C3[事件驱动]
                                C --> C4[任务调度]
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8 py-16">
        <!-- Introduction -->
        <section class="mb-20">
            <p class="text-lg leading-relaxed text-slate-700 mb-8">
                随着现代应用程序的复杂度不断增加，并发编程成为高效设计和实现系统的关键技术之一。尤其是在涉及到大量并发请求、高负载处理时，多线程技术不可避免地成为解决性能瓶颈的有效手段。然而，单纯的多线程编程并不足以保证系统的稳定性和高效性。为了高效管理多线程和并发操作，设计模式和架构设计的作用变得愈加重要。
            </p>
            
            <div class="grid grid-cols-1 md:grid-cols-2 gap-8 mb-12">
                <div class="bg-white p-6 rounded-xl shadow-md">
                    <div class="flex items-center mb-4">
                        <div class="w-10 h-10 rounded-full bg-purple-100 flex items-center justify-center mr-4">
                            <i class="fas fa-bolt text-purple-600"></i>
                        </div>
                        <h3 class="text-xl font-bold text-slate-800">并发优势</h3>
                    </div>
                    <p class="text-slate-600">充分利用多核处理器能力，提高系统吞吐量，实现更快的响应时间和更高的资源利用率。</p>
                </div>
                <div class="bg-white p-6 rounded-xl shadow-md">
                    <div class="flex items-center mb-4">
                        <div class="w-10 h-10 rounded-full bg-blue-100 flex items-center justify-center mr-4">
                            <i class="fas fa-exclamation-triangle text-blue-600"></i>
                        </div>
                        <h3 class="text-xl font-bold text-slate-800">并发挑战</h3>
                    </div>
                    <p class="text-slate-600">线程安全、死锁、竞态条件、上下文切换开销等问题需要精心设计来解决。</p>
                </div>
            </div>
        </section>

        <!-- Section 1 -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-1 bg-purple-600 mr-4"></div>
                <h2 class="text-3xl font-bold text-slate-800 font-serif">1. 并发编程的基本概念与挑战</h2>
            </div>

            <div class="mb-12">
                <h3 class="text-2xl font-bold text-slate-800 mb-4 flex items-center">
                    <span class="w-8 h-8 rounded-full bg-purple-100 text-purple-800 flex items-center justify-center mr-3">1.1</span>
                    并发编程的基本概念
                </h3>
                <p class="text-slate-700 leading-relaxed mb-6">
                    并发编程是指在同一时间段内，多个任务在同一个处理器或多个处理器上并行执行的技术。它主要解决如何利用计算机多核处理器，提高程序执行效率的问题。在 Java 中，基于多线程的并发编程模式非常常见。多线程允许在同一进程中同时执行多个线程，每个线程相互独立，执行不同的任务。
                </p>
            </div>

            <div>
                <h3 class="text-2xl font-bold text-slate-800 mb-4 flex items-center">
                    <span class="w-8 h-8 rounded-full bg-purple-100 text-purple-800 flex items-center justify-center mr-3">1.2</span>
                    并发编程面临的挑战
                </h3>
                <p class="text-slate-700 leading-relaxed mb-6">
                    并发编程虽然可以提高性能，但同时带来了多线程管理、线程安全、死锁等问题，开发者需要采取有效的措施来应对这些挑战。
                </p>
                
                <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6">
                    <div class="bg-white p-6 rounded-xl shadow-sm border-l-4 border-purple-500">
                        <h4 class="font-bold text-lg text-slate-800 mb-2">线程安全问题</h4>
                        <p class="text-slate-600">多个线程并发访问共享资源时，容易发生数据不一致的情况。</p>
                    </div>
                    <div class="bg-white p-6 rounded-xl shadow-sm border-l-4 border-red-500">
                        <h4 class="font-bold text-lg text-slate-800 mb-2">死锁问题</h4>
                        <p class="text-slate-600">多个线程因相互依赖的资源而进入互相等待的状态，导致程序无法继续执行。</p>
                    </div>
                    <div class="bg-white p-6 rounded-xl shadow-sm border-l-4 border-blue-500">
                        <h4 class="font-bold text-lg text-slate-800 mb-2">上下文切换开销</h4>
                        <p class="text-slate-600">频繁的线程切换会带来性能损失。</p>
                    </div>
                    <div class="bg-white p-6 rounded-xl shadow-sm border-l-4 border-green-500">
                        <h4 class="font-bold text-lg text-slate-800 mb-2">资源管理</h4>
                        <p class="text-slate-600">线程池、任务调度等资源的合理分配与管理。</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Section 2 -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-1 bg-purple-600 mr-4"></div>
                <h2 class="text-3xl font-bold text-slate-800 font-serif">2. 多线程设计模式</h2>
            </div>

            <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 mb-12">
                <div class="pattern-card bg-white rounded-xl shadow-md overflow-hidden transition duration-300">
                    <div class="bg-purple-600 h-2"></div>
                    <div class="p-6">
                        <div class="flex items-center justify-center w-16 h-16 rounded-full bg-purple-100 text-purple-600 mb-4 mx-auto">
                            <i class="fas fa-crown text-2xl"></i>
                        </div>
                        <h3 class="text-xl font-bold text-center text-slate-800 mb-2">单例模式</h3>
                        <p class="text-slate-600 text-center">确保类只有一个实例，并提供全局访问点。</p>
                    </div>
                </div>
                <div class="pattern-card bg-white rounded-xl shadow-md overflow-hidden transition duration-300">
                    <div class="bg-blue-600 h-2"></div>
                    <div class="p-6">
                        <div class="flex items-center justify-center w-16 h-16 rounded-full bg-blue-100 text-blue-600 mb-4 mx-auto">
                            <i class="fas fa-exchange-alt text-2xl"></i>
                        </div>
                        <h3 class="text-xl font-bold text-center text-slate-800 mb-2">生产者-消费者</h3>
                        <p class="text-slate-600 text-center">解耦生产与消费过程，提高系统吞吐量。</p>
                    </div>
                </div>
                <div class="pattern-card bg-white rounded-xl shadow-md overflow-hidden transition duration-300">
                    <div class="bg-green-600 h-2"></div>
                    <div class="p-6">
                        <div class="flex items-center justify-center w-16 h-16 rounded-full bg-green-100 text-green-600 mb-4 mx-auto">
                            <i class="fas fa-eye text-2xl"></i>
                        </div>
                        <h3 class="text-xl font-bold text-center text-slate-800 mb-2">观察者模式</h3>
                        <p class="text-slate-600 text-center">实现对象间的一对多依赖关系。</p>
                    </div>
                </div>
                <div class="pattern-card bg-white rounded-xl shadow-md overflow-hidden transition duration-300">
                    <div class="bg-orange-600 h-2"></div>
                    <div class="p-6">
                        <div class="flex items-center justify-center w-16 h-16 rounded-full bg-orange-100 text-orange-600 mb-4 mx-auto">
                            <i class="fas fa-users text-2xl"></i>
                        </div>
                        <h3 class="text-xl font-bold text-center text-slate-800 mb-2">线程池模式</h3>
                        <p class="text-slate-600 text-center">复用线程资源，减少创建销毁开销。</p>
                    </div>
                </div>
            </div>

            <!-- 2.1 -->
            <div class="mb-12">
                <h3 class="text-2xl font-bold text-slate-800 mb-4 flex items-center">
                    <span class="w-8 h-8 rounded-full bg-purple-100 text-purple-800 flex items-center justify-center mr-3">2.1</span>
                    单例模式（Singleton Pattern）
                </h3>
                <p class="text-slate-700 leading-relaxed mb-6">
                    在并发编程中，单例模式用于确保在整个系统中，某个类只有一个实例。这对于管理共享资源或全局状态非常有用。在多线程环境下，单例模式需要考虑线程安全的问题。Java 提供了多种实现单例模式的方式，其中最常用的是"双重检查锁"模式（Double-Checked Locking）：
                </p>
                
                <div class="code-block rounded-lg overflow-hidden mb-6">
                    <div class="flex items-center bg-slate-800 px-4 py-2">
                        <div class="flex space-x-2 mr-4">
                            <div class="w-3 h-3 rounded-full bg-red-500"></div>
                            <div class="w-3 h-3 rounded-full bg-yellow-500"></div>
                            <div class="w-3 h-3 rounded-full bg-green-500"></div>
                        </div>
                        <span class="text-slate-300 text-sm">Singleton.java</span>
                    </div>
                    <pre class="p-4 text-sm overflow-x-auto"><code class="text-slate-200">public class Singleton {
    private static volatile Singleton instance;

    private Singleton() {}

    public static Singleton getInstance() {
        if (instance == null) {
            synchronized (Singleton.class) {
                if (instance == null) {
                    instance = new Singleton();
                }
            }
        }
        return instance;
    }
}</code></pre>
                </div>
                
                <p class="text-slate-700 leading-relaxed">
                    在这个实现中，<span class="highlight font-mono bg-purple-100 px-1 rounded">volatile</span> 关键字确保了多线程环境下的内存可见性，避免了创建多个实例的情况。
                </p>
            </div>

            <!-- 2.2 -->
            <div class="mb-12">
                <h3 class="text-2xl font-bold text-slate-800 mb-4 flex items-center">
                    <span class="w-8 h-8 rounded-full bg-purple-100 text-purple-800 flex items-center justify-center mr-3">2.2</span>
                    生产者-消费者模式（Producer-Consumer Pattern）
                </h3>
                <p class="text-slate-700 leading-relaxed mb-6">
                    生产者-消费者模式是一种经典的并发设计模式，适用于多个线程处理队列中的任务。生产者将任务添加到共享队列中，消费者从队列中获取并处理任务。为了避免队列为空或满的情况，生产者和消费者需要通过线程同步机制进行协作。常见的实现方法是使用 <span class="highlight font-mono bg-purple-100 px-1 rounded">BlockingQueue</span>，它内部已经封装了线程同步和队列管理。
                </p>
                
                <div class="code-block rounded-lg overflow-hidden mb-6">
                    <div class="flex items-center bg-slate-800 px-4 py-2">
                        <div class="flex space-x-2 mr-4">
                            <div class="w-3 h-3 rounded-full bg-red-500"></div>
                            <div class="w-3 h-3 rounded-full bg-yellow-500"></div>
                            <div class="w-3 h-3 rounded-full bg-green-500"></div>
                        </div>
                        <span class="text-slate-300 text-sm">ProducerConsumerDemo.java</span>
                    </div>
                    <pre class="p-4 text-sm overflow-x-auto"><code class="text-slate-200">public class ProducerConsumerDemo {
    private static final BlockingQueue&lt;Integer&gt; queue = new ArrayBlockingQueue&lt;&gt;(10);

    public static void main(String[] args) {
        // 生产者线程
        Thread producer = new Thread(() -> {
            try {
                while (true) {
                    int item = new Random().nextInt(100);
                    queue.put(item);
                    System.out.println("Produced: " + item);
                }
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        });

        // 消费者线程
        Thread consumer = new Thread(() -> {
            try {
                while (true) {
                    int item = queue.take();
                    System.out.println("Consumed: " + item);
                }
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        });

        producer.start();
        consumer.start();
    }
}</code></pre>
                </div>
            </div>

            <!-- 2.3 -->
            <div class="mb-12">
                <h3 class="text-2xl font-bold text-slate-800 mb-4 flex items-center">
                    <span class="w-8 h-8 rounded-full bg-purple-100 text-purple-800 flex items-center justify-center mr-3">2.3</span>
                    观察者模式（Observer Pattern）
                </h3>
                <p class="text-slate-700 leading-relaxed mb-6">
                    观察者模式用于实现对象之间的一对多依赖关系。当一个对象的状态发生变化时，所有依赖于它的对象都会收到通知并自动更新。这在多线程环境下非常有用，特别是在事件驱动架构中。例如，可以通过 <span class="highlight font-mono bg-purple-100 px-1 rounded">java.util.Observable</span> 和 <span class="highlight font-mono bg-purple-100 px-1 rounded">java.util.Observer</span> 来实现。
                </p>
                
                <div class="code-block rounded-lg overflow-hidden mb-6">
                    <div class="flex items-center bg-slate-800 px-4 py-2">
                        <div class="flex space-x-2 mr-4">
                            <div class="w-3 h-3 rounded-full bg-red-500"></div>
                            <div class="w-3 h-3 rounded-full bg-yellow-500"></div>
                            <div class="w-3 h-3 rounded-full bg-green-500"></div>
                        </div>
                        <span class="text-slate-300 text-sm">ObserverPatternDemo.java</span>
                    </div>
                    <pre class="p-4 text-sm overflow-x-auto"><code class="text-slate-200">public class ObserverPatternDemo {
    public static void main(String[] args) {
        ObservableSubject subject = new ObservableSubject();
        Observer observer1 = new ConcreteObserver("Observer1");
        Observer observer2 = new ConcreteObserver("Observer2");

        subject.addObserver(observer1);
        subject.addObserver(observer2);

        subject.setState("State Changed!");
    }
}

class ObservableSubject extends Observable {
    private String state;

    public void setState(String state) {
        this.state = state;
        setChanged();
        notifyObservers(state);
    }
}

class ConcreteObserver implements Observer {
    private String name;

    public ConcreteObserver(String name) {
        this.name = name;
    }

    @Override
    public void update(Observable o, Object arg) {
        System.out.println(name + " received state change: " + arg);
    }
}</code></pre>
                </div>
            </div>

            <!-- 2.4 -->
            <div class="mb-12">
                <h3 class="text-2xl font-bold text-slate-800 mb-4 flex items-center">
                    <span class="w-8 h-8 rounded-full bg-purple-100 text-purple-800 flex items-center justify-center mr-3">2.4</span>
                    线程池模式（Thread Pool Pattern）
                </h3>
                <p class="text-slate-700 leading-relaxed mb-6">
                    线程池模式是一种常用的设计模式，目的是通过预先创建一定数量的线程并将任务分配给线程池管理的线程来实现线程复用，避免频繁创建和销毁线程带来的性能开销。在 Java 中，线程池可以通过 <span class="highlight font-mono bg-purple-100 px-1 rounded">ExecutorService</span> 实现。
                </p>
                
                <div class="code-block rounded-lg overflow-hidden mb-6">
                    <div class="flex items-center bg-slate-800 px-4 py-2">
                        <div class="flex space-x-2 mr-4">
                            <div class="w-3 h-3 rounded-full bg-red-500"></div>
                            <div class="w-3 h-3 rounded-full bg-yellow-500"></div>
                            <div class="w-3 h-3 rounded-full bg-green-500"></div>
                        </div>
                        <span class="text-slate-300 text-sm">ThreadPoolDemo.java</span>
                    </div>
                    <pre class="p-4 text-sm overflow-x-auto"><code class="text-slate-200">ExecutorService executor = Executors.newFixedThreadPool(4);
executor.submit(() -> {
    // 执行任务
});</code></pre>
                </div>
                
                <p class="text-slate-700 leading-relaxed">
                    线程池管理任务执行、调度和资源的利用，从而提高程序的效率和资源的利用率。
                </p>
            </div>
        </section>

        <!-- Section 3 -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-1 bg-purple-600 mr-4"></div>
                <h2 class="text-3xl font-bold text-slate-800 font-serif">3. 多线程架构设计</h2>
            </div>

            <div class="mb-12">
                <h3 class="text-2xl font-bold text-slate-800 mb-4 flex items-center">
                    <span class="w-8 h-8 rounded-full bg-purple-100 text-purple-800 flex items-center justify-center mr-3">3.1</span>
                    线程安全的设计
                </h3>
                <p class="text-slate-700 leading-relaxed mb-6">
                    多线程程序的设计首要任务是保证线程安全。为了确保多个线程并发执行时共享资源的正确性，常用的同步机制包括：
                </p>
                
                <div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-6">
                    <div class="bg-white p-4 rounded-lg shadow-sm border border-slate-200">
                        <h4 class="font-bold text-purple-600 mb-2 flex items-center">
                            <i class="fas fa-lock mr-2"></i> 锁机制
                        </h4>
                        <p class="text-slate-600 text-sm">通过 <code class="bg-purple-100 px-1 rounded">synchronized</code> 关键字或 <code class="bg-purple-100 px-1 rounded">ReentrantLock</code> 等显式锁保证线程对共享资源的独占访问。</p>
                    </div>
                    <div class="bg-white p-4 rounded-lg shadow-sm border border-slate-200">
                        <h4 class="font-bold text-blue-600 mb-2 flex items-center">
                            <i class="fas fa-unlock-alt mr-2"></i> 无锁编程
                        </h4>
                        <p class="text-slate-600 text-sm">使用原子操作（如 <code class="bg-blue-100 px-1 rounded">AtomicInteger</code>）或 CAS（Compare-And-Swap）机制，避免使用锁来提高性能。</p>
                    </div>
                    <div class="bg-white p-4 rounded-lg shadow-sm border border-slate-200">
                        <h4 class="font-bold text-green-600 mb-2 flex items-center">
                            <i class="fas fa-user-shield mr-2"></i> 线程局部存储
                        </h4>
                        <p class="text-slate-600 text-sm">每个线程都有自己的局部变量，避免线程之间的资源竞争。</p>
                    </div>
                </div>
            </div>

            <!-- 3.2 -->
            <div class="mb-12">
                <h3 class="text-2xl font-bold text-slate-800 mb-4 flex items-center">
                    <span class="w-8 h-8 rounded-full bg-purple-100 text-purple-800 flex items-center justify-center mr-3">3.2</span>
                    无阻塞架构
                </h3>
                <p class="text-slate-700 leading-relaxed mb-6">
                    在高并发系统中，阻塞是性能瓶颈的主要来源之一。为此，采用无阻塞架构可以有效提升系统的吞吐量和响应速度。Java 中的 <span class="highlight font-mono bg-purple-100 px-1 rounded">java.util.concurrent</span> 包提供了多种无阻塞数据结构，如 <span class="highlight font-mono bg-blue-100 px-1 rounded">ConcurrentHashMap</span>、<span class="highlight font-mono bg-blue-100 px-1 rounded">CopyOnWriteArrayList</span> 等，这些数据结构通过乐观锁或 CAS 操作来保证线程安全。
                </p>
            </div>

            <!-- 3.3 -->
            <div class="mb-12">
                <h3 class="text-2xl font-bold text-slate-800 mb-4 flex items-center">
                    <span class="w-8 h-8 rounded-full bg-purple-100 text-purple-800 flex items-center justify-center mr-3">3.3</span>
                    事件驱动架构（EDA）
                </h3>
                <p class="text-slate-700 leading-relaxed mb-6">
                    事件驱动架构（EDA）是一种高度解耦的架构设计模式，适用于大规模并发应用。在 EDA 中，系统通过事件的发布和订阅来处理任务和通信，避免了阻塞等待。通过事件驱动，可以将多线程任务拆解为多个异步处理的事件，提升并发处理能力。
                </p>
            </div>

            <!-- 3.4 -->
            <div class="mb-12">
                <h3 class="text-2xl font-bold text-slate-800 mb-4 flex items-center">
                    <span class="w-8 h-8 rounded-full bg-purple-100 text-purple-800 flex items-center justify-center mr-3">3.4</span>
                    任务调度与队列管理
                </h3>
                <p class="text-slate-700 leading-relaxed mb-6">
                    在多线程系统中，任务调度和队列管理至关重要。通过合理设计任务队列和调度策略，可以避免线程池资源过载和任务堆积，提升系统稳定性。
                </p>
                
                <div class="grid grid-cols-1 md:grid-cols-3 gap-6">
                    <div class="bg-white p-6 rounded-xl shadow-sm">
                        <div class="flex items-center justify-center w-12 h-12 rounded-full bg-orange-100 text-orange-600 mb-4 mx-auto">
                            <i class="fas fa-list-ol text-xl"></i>
                        </div>
                        <h4 class="font-bold text-center text-slate-800 mb-2">FIFO</h4>
                        <p class="text-slate-600 text-center text-sm">先进先出策略，适用于任务处理顺序固定的场景。</p>
                    </div>
                    <div class="bg-white p-6 rounded-xl shadow-sm">
                        <div class="flex items-center justify-center w-12 h-12 rounded-full bg-blue-100 text-blue-600 mb-4 mx-auto">
                            <i class="fas fa-sort-amount-up-alt text-xl"></i>
                        </div>
                        <h4 class="font-bold text-center text-slate-800 mb-2">优先级队列</h4>
                        <p class="text-slate-600 text-center text-sm">用于任务优先级不同的场景，根据优先级先后处理任务。</p>
                    </div>
                    <div class="bg-white p-6 rounded-xl shadow-sm">
                        <div class="flex items-center justify-center w-12 h-12 rounded-full bg-green-100 text-green-600 mb-4 mx-auto">
                            <i class="fas fa-clock text-xl"></i>
                        </div>
                        <h4 class="font-bold text-center text-slate-800 mb-2">延迟队列</h4>
                        <p class="text-slate-600 text-center text-sm">用于延迟执行任务的场景，任务在一定时间后自动执行。</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Section 4 -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-1 bg-purple-600 mr-4"></div>
                <h2 class="text-3xl font-bold text-slate-800 font-serif">4. 性能优化与瓶颈排查</h2>
            </div>

            <div class="mb-12">
                <h3 class="text-2xl font-bold text-slate-800 mb-4 flex items-center">
                    <span class="w-8 h-8 rounded-full bg-purple-100 text-purple-800 flex items-center justify-center mr-3">4.1</span>
                    资源管理优化
                </h3>
                <p class="text-slate-700 leading-relaxed">
                    高效的资源管理是并发编程中非常重要的一环。合理的线程池大小、任务队列容量、数据库连接池配置等，都能显著提升程序的并发性能。同时，减少线程上下文切换的次数，避免过多的线程竞争资源，能够减少系统开销。
                </p>
            </div>

            <div>
                <h3 class="text-2xl font-bold text-slate-800 mb-4 flex items-center">
                    <span class="w-8 h-8 rounded-full bg-purple-100 text-purple-800 flex items-center justify-center mr-3">4.2</span>
                    负载均衡与容错设计
                </h3>
                <p class="text-slate-700 leading-relaxed">
                    在并发编程中，负载均衡和容错设计至关重要。通过合理的负载均衡策略，将请求均匀分配给多个服务实例，从而避免单个实例过载。同时，设计良好的容错机制，确保系统在部分线程或服务失败时仍能继续运行。
                </p>
            </div>
        </section>

        <!-- Conclusion -->
        <section class="bg-white rounded-xl shadow-md p-8 mb-20 border border-purple-100">
            <div class="flex items-start">
                <div class="flex-shrink-0 mr-4 text-purple-600">
                    <i class="fas fa-lightbulb text-3xl"></i>
                </div>
                <div>
                    <h3 class="text-xl font-bold text-slate-800 mb-3">并发编程的关键要点</h3>
                    <p class="text-slate-700 mb-4">
                        现代并发编程不仅仅是简单地使用多线程，而是需要综合考虑设计模式、架构设计和性能优化等多个方面。从单例模式到生产者-消费者模式，从线程安全设计到无阻塞架构，每个环节都需要精心设计才能构建出高效稳定的并发系统。
                    </p>
                    <p class="text-slate-700">
                        通过本文介绍的多种模式和架构方法，开发者可以更好地应对并发编程中的各种挑战，设计出既能充分发挥多核处理器性能，又能保证系统稳定性的高质量应用程序。
                    </p>
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-slate-900 text-white py-12 px-4 sm:px-6 lg:px-8">
        <div class="max-w-6xl mx-auto">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-6 md:mb-0">
                    <h3 class="text-2xl font-bold mb-2">技术小馆</h3>
                    <p class="text-slate-400">探索编程艺术的深度与广度</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="text-purple-400 hover:text-purple-300 transition duration-300 flex items-center">
                        <i class="fas fa-link mr-2"></i> http://www.yuque.com/jtostring
                    </a>
                </div>
            </div>
            <div class="border-t border-slate-700 mt-8 pt-8 text-center text-slate-500 text-sm">
                &copy; 2023 技术小馆. 保留所有权利.
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'dark',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
        
        // 添加微交互效果
        document.querySelectorAll('.highlight').forEach(el => {
            el.addEventListener('mouseenter', () => {
                el.classList.add('bg-purple-100');
            });
            el.addEventListener('mouseleave', () => {
                setTimeout(() => {
                    el.classList.remove('bg-purple-100');
                }, 300);
            });
        });
    </script>
</body>
</html>
```